#!/bin/bash

# 检查是否提供了目录参数
if [ "$#" -ne 1 ]; then
    echo "Usage: $0 <directory>"
    exit 1
fi

# 获取目录路径
TARGET_DIR="$1"

# 检查目录是否存在
if [ ! -d "$TARGET_DIR" ]; then
    echo "Error: Directory does not exist."
    exit 1
fi

# 初始化计数器
counter=1

# 进入指定目录
cd "$TARGET_DIR"

# 遍历目录下的所有文本文件
for file in *.txt; do
    if [ -f "$file" ]; then
        # 获取文件的后缀
        extension="${file##*.}"
        # 构造新的文件名
        new_name="$counter.txt"
        # 重命名文件
        mv "$file" "$new_name"
        # 更新计数器
        ((counter++))
    fi
done

echo "Renaming completed. Text files are renamed in the order they were found."
